package f_collection;

import java.util.*;

public class HashtableEx{
	Hashtable ht = new Hashtable(10);

	public HashtableEx(){
		ht.put("1", "one");
		ht.put("2", "two");
		ht.put("3", "three");
		ht.put("4", "four");
		ht.put("5", "five");
	}

	public String get(String s){
		String result = (String)ht.get(s);
		return result;
	}

	public boolean getKey(String s){
		return ht.containsKey(s);
	}

	public boolean getValue(String s){
		return ht.containsValue(s);
	}

	public int size(){
		return ht.size();
	}

	public void allElements(){
		Enumeration e = ht.elements();
		System.out.println("all elements(1)------------");
	
		while(e.hasMoreElements()){
			System.out.println((String)e.nextElement());
		}
		
		Collection<String> it = ht.values();
		Object[] temp = (Object[])it.toArray();
		System.out.println("all elements (2)------------");
		System.out.println(Arrays.toString(temp));

	}

	public void allKeys(){
		Enumeration e = ht.keys();
		
		System.out.println("all keys------------");
		
		while(e.hasMoreElements()){
			System.out.println((String)e.nextElement());
		}
	}

	public static void main(String[] args){
		HashtableEx h = new HashtableEx();

		System.out.println(h.get("1"));
		System.out.println(h.size());

		//키값이존재 하는가 
		if(h.getKey("6")){
			System.out.println("ok");
		}
		else{
			System.out.println("fail");
		}

		// value가 존재 하는가
		if(h.getValue("five")){
			System.out.println("ok");
		}
		else{
			System.out.println("fail");
		}

		h.allElements();
		h.allKeys();

	}
}
